package org.alerve.android.resourcebuilder;

import org.alerve.android.resourcebuilder.Resource.ArrayType;
import org.alerve.android.resourcebuilder.Resource.ResourceType;
import org.alerve.android.resourcebuilder.fieldmodules.SpinnerArrayAdapter;
import org.alerve.android.resources.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

@Layout(R.layout.ui_test_activity)
public class UITestActivity extends Activity {

	@Resource
	Button applyButton;
	@Resource
	EditText editText;
	@Resource
	TextView outputTextView;
	@Resource
	@SpinnerArrayAdapter(R.array.string_array)
	Spinner selectSpinner;
	@Resource
	Spinner resultSpinner;

	@Resource(type = ResourceType.Array, arrayType = ArrayType.Integer)
	int[] intArray;

	@Resource(type = ResourceType.Array, arrayType = ArrayType.String)
	String[] stringArray;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ModuleDirector.getInstance().build(this);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, stringArray);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		resultSpinner.setAdapter(adapter);
	}

	public void apply(View target) {
		if (target == applyButton) {
			outputTextView.setText(editText.getText());
		}
	}

}
